package com.bilicraft.plugin.kexue.commands;

import java.io.File;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import com.bilicraft.plugin.kexue.ShellUser;

public class BiliCmdCd extends BiliCmd{
	public BiliCmdCd(){
		nofArgs = 1;
	}
	
	public boolean doExec(CommandSender sender, Command cmd, String label, String[] args, ShellUser shellUser){
		try{
			String cddir = shellUser.curdir+'/'+args[0];
			File fdir = new File(cddir);
			if(fdir.exists() && fdir.isDirectory()){
				shellUser.curdir = fdir.getCanonicalPath();
				sender.sendMessage("Directory changed to "+shellUser.curdir+".");
			}else{
				sender.sendMessage("Invalid path: "+cddir+".");
			}
			return true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
